﻿// ===============================================================================
// MvcConfigurationSection.cs
// EOS Web Framework
// ===============================================================================
// Copyright (c) EOS Development Group. All rights reserved.
// ===============================================================================

namespace EOS.Framework.Web.Mvc
{
    using System.Configuration;

    /// <summary>
    /// Indicates how the framework should behave, if an the requested
    /// web page cannot been found.
    /// </summary>
    public enum PageNotFoundBehaviour
    {
        /// <summary>
        /// Just throw an <see cref="WebPageNotFoundException"/>.
        /// </summary>
        ThrowException,
        /// <summary>
        /// Response a 404 status.
        /// </summary>
        Response404,
        /// <summary>
        /// Redirect to the specified error page.
        /// </summary>
        Redirect
    }

    /// <summary>
    /// The configuration section for the mvc framework.
    /// </summary>
    public sealed class MvcConfigurationSection : ConfigurationSection
    {
        /// <summary>
        /// Defines, how the mvc framework should behave, if the requested web page cannot been found.
        /// </summary>
        /// <value>The page not found behaviour.</value>
        [ConfigurationProperty("pageNotFoundBehaviour", IsRequired=false)]
        public PageNotFoundBehaviour PageNotFoundBehaviour
        {
            get { return (PageNotFoundBehaviour)this["pageNotFoundBehaviour"]; }
            set { this["pageNotFoundBehaviour"] = value; }
        }

        /// <summary>
        /// Gets or sets the time, how long the markup files should be stored in the global cache.
        /// </summary>
        /// <value>The cache time.</value>
        [ConfigurationProperty("cacheTime", IsRequired=false, DefaultValue=60), IntegerValidator(MinValue=60)]
        public int CacheTime
        {
            get { return (int)this["cacheTime"]; }
            set { this["cacheTime"] = value; }
        }

        /// <summary>
        /// Gets or sets the error site, where to redirect, when a error occurs.
        /// </summary>
        /// <value>The error site.</value>
        /// <remarks>The framework will redirect to the specified site, if the <see cref="PageNotFoundBehaviour"/> is 
        /// set to Redirect and the page cannot been found.</remarks>
        [ConfigurationProperty("errorSite", IsRequired=true)]
        public string ErrorSite
        {
            get { return (string)this["errorSite"]; }
            set { this["errorSite"] = value; }
        }

        /// <summary>
        /// Gets or sets a flag, indicating, if the application is in trace mode.
        /// </summary>
        /// <value>A flag indicating if in trace mode.</value>
        [ConfigurationProperty("traceMode", IsRequired=false, DefaultValue=false)]
        public bool TraceMode
        {
            get { return (bool)this["traceMode"]; }
            set { this["traceMode"] = value; }
        }
    }
}
